{{template "layout/layout_admin.html" .}}

{{define "style"}}

{{end}}
{{define "content"}}

<div class="layui-fluid main" style="margin:15px;">


    <fieldset class="layui-elem-field layui-field-title" style="margin-top:20px;">
        <legend>项目发布</legend>
    </fieldset>


    <table id="pj_table" lay-filter="pj_table"></table>

</div>

{{end}}


{{define "script"}}
<script type="text/html" id="tableTool">
    <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="publish">发布申请</a>
</script>

<script type="text/html" id="alertConsole">
    <textarea readonly style="width: 425px; height:330px; background-color: #0C0C0C; color: #fff;padding: 10px; ">${result}</textarea>
</script>
<script>
    layui.use(['jquery','table','form'], function() {
    {{template "layout/baseJs.html" .}}
        var table = layui.table,
                $ = layui.jquery,
                form = layui.form,
                layer = layui.layer,
                laytpl = layui.laytpl;



        table.render({
            elem: '#pj_table'
            ,height: 550
            ,url: '{{urlfor "ProjectController.ListApi"}}' //数据接口
            ,page: true //开启分页
            ,cols: [[ //表头
                {field: 'id', title: 'ID', width:80, sort: true, fixed: 'left'}
                ,{field: 'name', title: '项目名称'}
                ,{field: 'from_path', title: '仓库地址'}
                ,{field: 'account', title: '帐号', width:280}
                ,{field: 'updated_at', title: '最后修改',width:250}
                ,{fixed: 'right', title: '操作', width:250, align:'center', toolbar: '#tableTool'}
            ]]
        });

        //监听工具条
        table.on('tool(pj_table)', function(obj){
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event;
            var tr = obj.tr;

            if(layEvent === 'publish'){ //删除
                var url='{{urlfor "PublishController.NewPub"}}'
                layer.load(2);
                $.ajax({
                    type: "GET",
                    url: url,
                    data: {id:data.id},
                    success: function(json){
                        layer.closeAll('loading');
                        if(json.status != 200){
                            QI.errorAlert(json.info);
                            return false;
                        }
                        QI.successAlert(json.info);

                        var tplData = {result:json.data};
                        var gettpl = document.getElementById('alertConsole').innerHTML;
                        var layHtml = juicer(gettpl, tplData);
                        layer.open({
                            title: '执行结果',
                            type: 1,
                            skin: 'layui-layer-rim', //加上边框
                            area: ['450px', '460px'], //宽高
                            btn: ['确认'],
                            content: layHtml
                        });

                    },
                    error:function(e){
                        layer.closeAll('loading');
                        QI.errorAlert('系统出小差了（'+e.statusText+'）');
                    }
                });

            }
        });


    });
</script>

{{end}}
